package base.json.fastjson.demo02;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
    private Integer id;
    private String name;
    private Integer age;
    private BigDecimal salary;
    private Sex sex;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime birth;

    public User(String name, Integer age, BigDecimal salary){
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public User(Integer id, String name, Integer age, LocalDateTime birth){
        this.id = id;
        this.name = name;
        this.age = age;
        this.birth = birth;
    }


    public User(String name, Integer age, BigDecimal salary, LocalDateTime birth){
        this.name = name;
        this.age = age;
        this.salary = salary;
        this.birth = birth;
    }

    public User(String name, Sex sex){
        this.name = name;
        this.sex = sex;
    }

}

enum Sex {
    Male(0,"男"), FEMALE(1,"女");

    @Getter
    private Integer code;
    @Getter
    private String des;

    private Sex(Integer code, String des){
        this.code = code;
        this.des = des;
    }

    @Override
    public String toString() {
        return this.getDes();
//        return "Sex{code=" + code + ", des='" + des + "'}";
    }
}
